Skip to content

fix: decode RESP3 attribute replies instead of failing the connection - #2213

Merged
PavelPashov merged 3 commits into
redis:mainfrom
Develop-KIM:fix-resp3-attribute
Oct 7, 2026
Merged

PavelPashov merged 3 commits into
redis:mainfrom
Develop-KIM:fix-resp3-attribute

Conversation

@Develop-KIM

@Develop-KIM Develop-KIM commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2212.

ioredis defaults to protocol: 3, but the decoder has no case for the RESP3 attribute type (|, 124), so one attribute reply ends the connection: the decoder throws Unknown RESP type 124 "|", DataHandler treats it as a fatal protocol error, and everything in flight on that socket is dropped. DEBUG PROTOCOL attrib reproduces it; RedisModule_ReplyWithAttribute is public, so a module can produce one in normal use.

An attribute is metadata for the reply behind it rather than a reply of its own, so:

  • Top level — the attribute map is consumed and #decodeTypeValue returns without invoking a callback, which leaves the main loop to decode the real reply that follows. Nothing extra reaches onReply, so the command queue stays aligned.
  • Nested (array/set element, map key or value) — the attribute is consumed and the element after it takes its place, through #decodeAttribute / #continueDecodeAttribute so it still resumes correctly when a chunk ends in the middle of an attribute.

The contents are discarded. The spec allows ignoring them and this keeps the change to the parse-and-skip the connection needs; surfacing them to callers would be an API decision for a separate change.

Tests

test/unit/resp/decoder.ts gains an Attribute block: the exact DEBUG PROTOCOL attrib wire format, an empty attribute, two in a row, before an error, before a push, on an array element, on a nested array element, on a map key and on a map value, on a Set element, and one whose own value is a map. The existing harness runs every case as a single chunk, byte by byte, and split at each byte boundary, so the resumable paths are covered — 33 of those assertions fail without the decoder change.

Verified against Redis 8.8.0: npm run test:js is green (2684 passing), as are npm run build, npx tsd and npm run lint. End to end, debug protocol attrib now returns Some real reply following the attribute and the connection stays up. The cluster suite needs the 3000-3005 nodes, which I couldn't start locally; its results are identical with and without this change.

This was written with AI assistance; the behaviour and the tests are ones I verified myself.


Note

Medium Risk
Touches core RESP parsing and reply dispatch; behavior change is scoped to skipping metadata, but incorrect attribute handling could misalign replies or break streaming decode paths.

Overview
Fixes fatal protocol errors when Redis sends RESP3 attribute (|) replies on the default RESP3 connection—previously the decoder threw on type 124 and the socket was torn down.

The decoder now recognizes ATTRIBUTE, parses the attribute payload as a map, and discards it (not exposed to onReply). At the top level, only the following real reply is delivered so the command queue stays aligned. Nested (arrays, sets, map keys/values), the attribute is skipped and the next value occupies that slot, with #decodeAttribute / #continueDecodeAttribute preserving chunk-boundary resume behavior. Map keys still go through the string key path after an attribute (including __proto__ handling).

Unit tests cover DEBUG PROTOCOL attrib wire format, attributes on array elements, and on a __proto__ map key.

Reviewed by Cursor Bugbot for commit a9f096b. Bugbot is set up for automated code reviews on this repo. Configure here.

ioredis defaults to protocol 3, but the decoder has no case for the RESP3
attribute type (`|`, 124). A single attribute reply therefore ends the
connection: the decoder throws "Unknown RESP type 124", DataHandler turns
that into a fatal protocol error, and every command in flight on the socket
is dropped. `DEBUG PROTOCOL attrib` reproduces it, and the public module API
(`RedisModule_ReplyWithAttribute`) lets any module produce one.

An attribute is metadata for the reply behind it, not a reply of its own, so
at the top level the attribute map is consumed without invoking a callback -
the main loop then decodes the real reply that follows - and nested in an
array, set or map the element after the attribute takes its place.

The contents are discarded, which the spec allows and which is all the
connection needs; surfacing them to callers would be a separate API change.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 5e056a9. Configure here.

Comment thread lib/resp/decoder.ts Resolved
The first commit resumed every attributed element through #decodeNestedType,
so a map key behind an attribute followed typeMapping instead of being coerced
to a string like any other key. With blob strings mapped to Buffer - what both
of DataHandler's presets do - that key came back as a Buffer from a Map, so
map.get("foo") missed it, and in the object path it walked past the
`__proto__` guard in #decodeMapAsObject, whose own-property check compares
against a string. A reply with an attributed `__proto__` key and an object
value then changed the decoded object's prototype.

Pass the decoder for the position the attribute was found in, so a key resumes
through #decodeMapKey and everything else through #decodeNestedType.
@Develop-KIM

Copy link
Copy Markdown
Contributor Author

Bugbot was right about the map keys, fixed in 3e7c9e6.

Resuming through #decodeNestedType meant an attributed key followed typeMapping instead of being coerced to a string. With blob strings mapped to Buffer (both of DataHandler's presets do that) the key came back as a Buffer, so map.get("foo") missed it, and in the object path it got past the __proto__ guard in #decodeMapAsObject, which compares against a string — %1\r\n|1\r\n+a\r\n+b\r\n$9\r\n__proto__\r\n*1\r\n:1\r\n changed the decoded object's prototype.

Now the attribute resumes with the decoder for the position it was found in: #decodeMapKey for a key, #decodeNestedType everywhere else. Three tests cover it (attributed key with Buffer-mapped blob strings, the same as a Map, and the __proto__ key); the last two fail without the change.

@PavelPashov

Copy link
Copy Markdown
Contributor

@Develop-KIM Thanks for the PR! I'll have a look.

@PavelPashov PavelPashov left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Develop-KIM, and thanks for the careful work here.

To be upfront: I don't think this is a real-world issue. In practice the only things that send RESP3 attributes are DEBUG PROTOCOL attrib and Redis's own test module. I couldn't find any public module that calls RedisModule_ReplyWithAttribute, and nobody has reported this from production. I'm still happy to merge it as a small spec-conformance fix, because a RESP3 client shouldn't drop the connection on a valid RESP3 type.

Because of that, I'd like the change to look as small as it really is. A large test block and long comments make it look like an important feature area, and that misleads whoever works on the decoder next. Could you:

  • Trim the Attribute tests to one per decoder path. The harness already runs every chunk split, so these three cover everything the patch touches:
    • DEBUG PROTOCOL attrib (top level)
    • on an array element (nested)
    • on a __proto__ map key with Buffer mapping (map-key path and prototype guard)
  • Cut the decoder comments to one line per case, e.g. // RESP3 attribute: consume and discard, then decode the decorated value.

Happy to approve once that's in.

Three cases cover what the patch touches - top level, nested, and the
map-key path with Buffer mapping - and the decoder comments are down to
one line per case.
@Develop-KIM

Copy link
Copy Markdown
Contributor Author

Both done in a9f096b — the three cases you listed are what's left, and each decoder case is down to a single-line comment.

I re-ran the trimmed set against an unpatched decoder to make sure nothing lost coverage: all three go red without the fix, and the __proto__ one is still the only test that catches the map-key path. Full unit + functional suite is green.

@PavelPashov PavelPashov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PavelPashov
PavelPashov merged commit 6a8cb3e into redis:main Oct 7, 2026
22 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.1.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RESP3 attribute replies are rejected as an unknown type and kill the connection

2 participants